<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 汪利东,2016-04-19 09:39
// +----------------------------------------------------------------------

namespace Delivery\Controller;


use Think\Controller;

class LoginController extends Controller
{

    /**
     * 登录
     */
    public function handleLogin()
    {
        $map['account'] = I('post.account');
        $map['password'] = sha1(I('post.password'));
        $r = M('delivery_man')->where($map)->find();
        if (empty($r)) {
            die(json_encode(['code' => 0, 'msg' => '用户名或密码错误']));
        } else {
            session('delivery_man', $r);
            die(json_encode(['code' => 1]));
        }
    }

    /**
     * 登出
     */
    public function handleLogout()
    {
        session('delivery_man', null);
        $this->redirect('Login/index');
    }
}